﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Aribaccio.Datum
{
    /// <summary>
    /// 数据库连接操作基本服务接口
    /// </summary>
    public interface IDataServiceBase
    {
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItem">对象模型实体</param>
        /// <returns>返回处理结果</returns>
        Result Insert<T>(T argItem) where T : class;
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItems">对象模型实体集合</param>
        /// <returns></returns>
        Result Insert<T>(List<T> argItems) where T : class;
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItem">对象模型实体</param>
        /// <returns>返回异步处理结果</returns>
        Task<Result> InsertTask<T>(T argItem) where T : class;
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItems">对象模型实体集合</param>
        /// <returns>返回异步处理结果</returns>
        Task<Result> InsertTask<T>(List<T> argItems) where T : class;

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItem">对象模型实体</param>
        /// <returns>返回处理结果</returns>
        Result Update<T>(T argItem) where T : class;
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItems">对象模型实体集合</param>
        /// <returns>返回处理结果</returns>
        Result Update<T>(List<T> argItems) where T : class;
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItem">对象模型实体</param>
        /// <returns>返回异步处理结果</returns>
        Task<Result> UpdateTask<T>(T argItem) where T : class;
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItems">对象模型实体集合</param>
        /// <returns>返回异步处理结果</returns>
        Task<Result> UpdateTask<T>(List<T> argItems) where T : class;
        /// <summary>
        /// 更新数据[批量Lambda]
        /// </summary>
        /// <param name="argItem">要修改实体中 修改后的属性 </param>
        /// <param name="argWhereLambda">查询实体的条件</param>
        /// <param name="argProNames">Lambda的形式表示要修改的实体属性名</param>
        /// <returns></returns>
        Result UpdateWhere<T>(T argItem, Expression<Func<T, bool>> argWhereLambda, params string[] argProNames) where T : class;
        /// <summary>
        /// 更新数据[批量非Lambda]
        /// </summary>
        /// <param name="argItem">要修改实体中 修改后的属性 </param>
        /// <param name="argWhereLambda">查询实体的条件</param>
        /// <param name="argProNames">Lambda的形式表示要修改的实体属性名</param>
        /// <returns></returns>
        Task<Result> UpdateWhereTask<T>(T argItem, Expression<Func<T, bool>> argWhereLambda, params string[] argProNames) where T : class;

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItem">对象模型实体</param>
        /// <param name="argSlaveType">主从数据库类型</param>
        /// <returns>返回处理结果</returns>
        Result Delete<T>(T argItem) where T : class;
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItems">对象模型实体集合</param>
        /// <returns>返回处理结果</returns>
        Result Delete<T>(List<T> argItems) where T : class;
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItem">对象模型实体</param>
        /// <param name="argSlaveType">主从数据库类型</param>
        /// <returns>返回处理结果</returns>
        Task<Result> DeleteTask<T>(T argItem) where T : class;
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argItems">对象模型实体集合</param>
        /// <returns>返回处理结果</returns>
        Task<Result> DeleteTask<T>(List<T> argItems) where T : class;
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argDelWhere">匿名函数查询条件</param>
        /// <returns></returns>
        Result DeleteWhere<T>(Expression<Func<T, bool>> argDelWhere) where T : class;
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argDelWhere">匿名函数查询条件</param>
        /// <returns></returns>
        Task<Result> DeleteWhereTask<T>(Expression<Func<T, bool>> argDelWhere) where T : class;

        /// <summary>
        /// 数据保存[只能批量增或删或改]
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argDBOperateType">数据库操作类型</param>
        /// <param name="argItems">对象模型实体或实体集合</param>
        /// <returns>返回处理结果</returns>
        Result ChangesSave<T>(DBOperateType argDBOperateType, params T[] argItems) where T : class;
        /// <summary>
        /// 执行增加,删除,修改操作(或调用存储过程)
        /// </summary>
        /// <param name="argSQLText">执行的T-SQL命令：SQL语句 或 存储过程名称</param>
        /// <param name="argCommandParms">行的T-SQL命令参数：可变参数数组</param>
        /// <returns></returns>
        Result ChangesExecuteSQL(string argSQLText, params DbParameter[] argCommandParms);
        /// <summary>
        /// 数据保存异步[只能批量增或删或改]
        /// </summary>
        /// <returns></returns>
        Task<Result> ChangesSaveTask<T>(DBOperateType argDBOperateType, params T[] argItems) where T : class;
        /// <summary>
        /// 执行增加,删除,修改操作(或调用存储过程)
        /// </summary>
        /// <param name="argSQLText">执行的T-SQL命令：SQL语句 或 存储过程名称</param>
        /// <param name="argCommandParms">行的T-SQL命令参数：可变参数数组</param>
        /// <returns></returns>
        Task<Result> ChangesExecuteSQLTask(string argSQLText, params DbParameter[] argCommandParms);

        /// <summary>
        /// 查询是否存在[根据唯一编码]
        /// </summary>
        /// <param name="argUniqueCode">唯一编码</param>
        /// <returns></returns>
        Result Exsits<T>(object argUniqueCode) where T : class;
        /// <summary>
        /// 查询是否存在[根据查询条件Lambda]
        /// </summary>
        /// <param name="argUniqueCode">唯一编码</param>
        /// <returns></returns>
        Result Exsits<T>(Expression<Func<T, bool>> argWhereLambda) where T : class;

        /// <summary>
        /// 查询数据[根据唯一编码]
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argUniqueCode">唯一编码</param>
        /// <returns></returns>
        ResultModel<T> SelectUnique<T>(object argUniqueCode) where T : class;
        /// <summary>
        /// 查询数据[根据条件查询]
        /// </summary>
        /// <param name="argWhereLambda">查询条件(lambda表达式的形式生成表达式目录树)</param>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns></returns>
        ResultModel<T> SelectModelItem<T>(Expression<Func<T, bool>> argWhereLambda, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[全部数据]
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns>实体对象集合</returns>
        IQueryable<T> SelectQueryable<T>(ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[根据条件查询]
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argWhereLambda">查询条件(lambda表达式的形式生成表达式目录树)</param>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns>实体对象集合</returns>
        IQueryable<T> SelectQueryable<T>(Expression<Func<T, bool>> argWhereLambda, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[全部数据]
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns>实体对象集合信息</returns>
        ResultList<T> SelectModelItems<T>(ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[根据条件查询]
        /// </summary>
        /// <param name="argWhereLambda">查询条件(lambda表达式的形式生成表达式目录树)</param>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns></returns>
        ResultList<T> SelectModelItems<T>(Expression<Func<T, bool>> argWhereLambda, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[根据条件查询和名称排序]
        /// </summary>
        /// <param name="argWhereLambda">查询条件</param>
        /// <param name="argSortName">排序名称</param>
        /// <param name="argSortDirection">asc 或 desc</param>
        ///  <param name="argTrackStatus">是否跟踪状态，默认是跟踪的</param>
        /// <returns></returns>
        ResultList<T> SelectModelItems<T>(Expression<Func<T, bool>> argWhereLambda, string argSortName, string argSortDirection, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[根据条件查询和Lambda排序]
        /// </summary>
        /// <typeparam name="Tkey">排序字段类型</typeparam>
        /// <param name="argWhereLambda">查询条件</param>
        /// <param name="argOrderLambda">排序条件</param>
        /// <param name="argSortStatus">排序状态【Yes升序,No降序/倒序】</param>
        ///  <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns></returns>
        ResultList<T> SelectModelItems<T, Tkey>(Expression<Func<T, bool>> argWhereLambda, Expression<Func<T, Tkey>> argOrderLambda, ExecuteStatus argSortStatus = ExecuteStatus.Yes, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询分页数据[根据条件查询和Lambda排序]
        /// </summary>
        /// <typeparam name="Tkey">排序字段类型</typeparam>
        /// <param name="argPageIndex">页码</param>
        /// <param name="argPageSize">页容量/每页数量</param>
        /// <param name="argWhereLambda">查询条件</param>
        /// <param name="argOrderLambda">排序条件</param>
        /// <param name="argSortStatus">排序状态【Yes升序,No降序/倒序】</param>
        ///  <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns></returns>
        ResultListPage<T> SelectModelItemsPager<T, Tkey>(int argPageIndex, int argPageSize, Expression<Func<T, bool>> argWhereLambda, Expression<Func<T, Tkey>> argOrderLambda, ExecuteStatus argSortStatus = ExecuteStatus.Yes, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;

        /// <summary>
        /// 查询数据[根据唯一编码]
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argUniqueCode">唯一编码</param>
        /// <returns></returns>
        Task<ResultModel<T>> SelectUniqueTask<T>(object argUniqueCode) where T : class;
        /// <summary>
        /// 查询数据[根据条件查询]
        /// </summary>
        /// <param name="argWhereLambda">查询条件(lambda表达式的形式生成表达式目录树)</param>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns></returns>
        Task<ResultModel<T>> SelectModelItemTask<T>(Expression<Func<T, bool>> argWhereLambda, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[全部数据]
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns>异步实体对象集合信息</returns>
        Task<ResultList<T>> SelectModelItemsTask<T>(ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[根据条件查询]
        /// </summary>
        /// <param name="argWhereLambda">查询条件(lambda表达式的形式生成表达式目录树)</param>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns></returns>
        Task<ResultList<T>> SelectModelItemsTask<T>(Expression<Func<T, bool>> argWhereLambda, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[根据条件查询和名称排序]
        /// </summary>
        /// <param name="argWhereLambda">查询条件</param>
        /// <param name="argSortName">排序名称</param>
        /// <param name="argSortDirection">asc 或 desc</param>
        ///  <param name="argTrackStatus">是否跟踪状态，默认是跟踪的</param>
        /// <returns></returns>
        Task<ResultList<T>> SelectModelItemsTask<T>(Expression<Func<T, bool>> argWhereLambda, string argSortName, string argSortDirection, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询数据[根据条件查询和Lambda排序]
        /// </summary>
        /// <typeparam name="Tkey">排序字段类型</typeparam>
        /// <param name="argWhereLambda">查询条件</param>
        /// <param name="argOrderLambda">排序条件</param>
        /// <param name="argSortStatus">排序状态【Yes升序,No降序/倒序】</param>
        ///  <param name="argTrackStatus">是否跟踪状态，默认是跟踪的</param>
        /// <returns></returns>
        Task<ResultList<T>> SelectModelItemsTask<T, Tkey>(Expression<Func<T, bool>> argWhereLambda, Expression<Func<T, Tkey>> argOrderLambda, ExecuteStatus argSortStatus = ExecuteStatus.Yes, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;
        /// <summary>
        /// 查询分页数据[根据条件查询和Lambda排序]
        /// </summary>
        /// <typeparam name="Tkey">排序字段类型</typeparam>
        /// <param name="argPageIndex">页码</param>
        /// <param name="argPageSize">页容量/每页数量</param>
        /// <param name="argWhereLambda">查询条件</param>
        /// <param name="argOrderLambda">排序条件</param>
        /// <param name="argSortStatus">排序状态【Yes升序,No降序/倒序】</param>
        ///  <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <returns></returns>
        Task<ResultListPage<T>> SelectModelItemsPagerTask<T, Tkey>(int argPageIndex, int argPageSize, Expression<Func<T, bool>> argWhereLambda, Expression<Func<T, Tkey>> argOrderLambda, ExecuteStatus argSortStatus = ExecuteStatus.Yes, ExecuteStatus argTrackStatus = ExecuteStatus.No) where T : class;

        /// <summary>
        /// 查询数据[执行SQL语句操作]
        /// 注：查询必须返回实体的所有属性字段；结果集中列名必须与属性映射的项目匹配；查询中不能包含关联数据
        /// 除Select以外其他的SQL语句无法执行
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argSQLText">执行的T-SQL命令：SQL语句 或 存储过程名称</param>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <param name="argCommandParms">行的T-SQL命令参数：可变参数数组</param>
        /// <returns></returns>
        ResultList<T> SelectExecuteSQL<T>(string argSQLText, ExecuteStatus argTrackStatus = ExecuteStatus.No, params DbParameter[] argCommandParms) where T : class;
        /// <summary>
        /// 查询数据[执行SQL语句操作]
        /// 注：查询必须返回实体的所有属性字段；结果集中列名必须与属性映射的项目匹配；查询中不能包含关联数据
        /// 除Select以外其他的SQL语句无法执行
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argSQLText">执行的T-SQL命令：SQL语句 或 存储过程名称</param>
        /// <param name="argWhereLambda">执行的T-SQL命令：查询Lambda条件</param>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <param name="argCommandParms">行的T-SQL命令参数：可变参数数组</param>
        /// <returns></returns>
        ResultList<T> SelectExecuteSQL<T>(string argSQLText, Expression<Func<T, bool>> argWhereLambda, ExecuteStatus argTrackStatus = ExecuteStatus.No, params DbParameter[] argCommandParms) where T : class;
        /// <summary>
        /// 查询数据[执行SQL语句操作]
        /// 注：查询必须返回实体的所有属性字段；结果集中列名必须与属性映射的项目匹配；查询中不能包含关联数据
        /// 除Select以外其他的SQL语句无法执行
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argSQLText">执行的T-SQL命令：SQL语句 或 存储过程名称</param>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <param name="argCommandParms">行的T-SQL命令参数：可变参数数组</param>
        /// <returns></returns>
        Task<ResultList<T>> SelectExecuteSQLTask<T>(string argSQLText, ExecuteStatus argTrackStatus = ExecuteStatus.No, params DbParameter[] argCommandParms) where T : class;
        /// <summary>
        /// 查询数据[执行SQL语句操作]
        /// 注：查询必须返回实体的所有属性字段；结果集中列名必须与属性映射的项目匹配；查询中不能包含关联数据
        /// 除Select以外其他的SQL语句无法执行
        /// </summary>
        /// <typeparam name="T">对象模型</typeparam>
        /// <param name="argSQLText">执行的T-SQL命令：SQL语句 或 存储过程名称</param>
        /// <param name="argWhereLambda">执行的T-SQL命令：查询Lambda条件</param>
        /// <param name="argTrackStatus">是否跟踪状态，默认是不跟踪的</param>
        /// <param name="argCommandParms">行的T-SQL命令参数：可变参数数组</param>
        /// <returns></returns>
        Task<ResultList<T>> SelectExecuteSQLTask<T>(string argSQLText, Expression<Func<T, bool>> argWhereLambda, ExecuteStatus argTrackStatus = ExecuteStatus.No, params DbParameter[] argCommandParms) where T : class;

    }
}
